package us.mooresr.geartrack.server.handler;

import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.DeleteItem;
import us.mooresr.geartrack.shared.action.DeleteItemAction;
import us.mooresr.geartrack.shared.action.DeleteItemResult;
import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;

public class DeleteItemActionHandler implements
		ActionHandler<DeleteItemAction, DeleteItemResult> {

	@Inject
	public DeleteItemActionHandler() {
	}

	@Override
	public DeleteItemResult execute(DeleteItemAction action, ExecutionContext context)
			throws ActionException {
		DAO dao = new DAO();
		
		dao.ofy().delete(action.getItemIn());
		
		return new DeleteItemResult(action.getItemIn());
	}

	@Override
	public void undo(DeleteItemAction action, DeleteItemResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<DeleteItemAction> getActionType() {
		return DeleteItemAction.class;
	}
}
